package com.study.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.study.model.BannerRes
import com.study.model.TypeRes
import com.study.service.ApiService
import com.study.commen.service.RetrofitClient
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class HomeViewmodel : ViewModel() {
    val type = MutableLiveData<TypeRes>()
    fun getData() {
        val apiService = RetrofitClient.get().create(ApiService::class.java)
        val subscribe = apiService.getData().observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe {
                type.postValue(it)
            }
    }

    val banner = MutableLiveData<BannerRes>()
    fun getBanner() {
        val apiService = RetrofitClient.get().create(ApiService::class.java)
        val subscribe = apiService.getBanner().observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe {
                banner.postValue(it)
            }
    }
}